// Decompiled by DJ v3.9.9.91 Copyright 2005 Atanas Neshkov  Date: 2008-9-8 20:38:51
// Home Page : http://members.fortunecity.com/neshkov/dj.html  - Check often for new version!
// Decompiler options: packimports(3) 
// Source File Name:   t_role_Manager.java

package com.creawor.hz_market.t_role;

import com.creawor.imei.base.BaseAction;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Session;
import org.apache.struts.action.*;

// Referenced classes of package com.creawor.hz_market.t_role:
//            t_role_QueryMap, t_role_Form, t_role_EditMap

public class t_role_Manager extends BaseAction {

	public t_role_Manager() {
	}

	public String doList(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		String pagenos = request.getParameter("pageno");
		String pagesizes = request.getParameter("pagesize");
		try {
			pageno = Integer.valueOf(pagenos);
		} catch (NumberFormatException e) {
			pageno = new Integer(1);
		}
		if (pagesizes != null)
			pagesize = Integer.valueOf(pagesizes.trim());
		t_role_QueryMap query_map = new t_role_QueryMap();
		query_map.pageno = pageno;
		query_map.pagesize = pagesize;
		java.util.Iterator sl = null;
		if (sql_string == null || sql_string.equals("")
				|| sql_string.equalsIgnoreCase("null")) {
			sl = query_map.findAll().iterator();
		} else {
			sl = query_map.findAll(sql_string, sql_param);
			request.setAttribute("sql_string", sql_string);
			request.setAttribute("sql_param", sql_param_str);
		}
		request.setAttribute("sl", sl);
		request.setAttribute("curpageno", pageno);
		if (pageno.intValue() > 1)
			request.setAttribute("prepage", new Integer(pageno.intValue() - 1));
		else
			request.setAttribute("prepage", new Integer(1));
		int totalpage = 0;
		if (pagesizes != null) {
			if (query_map.totalrow % pagesize.intValue() == 0)
				totalpage = query_map.totalrow / pagesize.intValue();
			else
				totalpage = query_map.totalrow / pagesize.intValue() + 1;
		}
		if (pageno.intValue() > totalpage) {
			totalpage = pageno.intValue();
		}
		request.setAttribute("totalpage", new Integer(totalpage));
		if (pageno.intValue() < totalpage)
			request
					.setAttribute("nextpage",
							new Integer(pageno.intValue() + 1));
		else
			request.setAttribute("nextpage", new Integer(totalpage));
		return "list";
	}

	public String doDetail(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		try {
			request.setAttribute("sql_string", sql_string);
			request.setAttribute("sql_param", sql_param_str);
			String pageno = request.getParameter("pageno");
			request.setAttribute("pageno", pageno);
		} catch (RuntimeException e1) {
			e1.printStackTrace();
		}
		t_role_QueryMap sqm = new t_role_QueryMap();
		String uid = request.getParameter("id");
		t_role_Form sf = null;
		sf = sqm.getByID(uid);
		request.setAttribute("t_role_Form", sf);
		return "detail";
	}

	public String doCreate(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		try {
			request.setAttribute("sql_string", sql_string);
			request.setAttribute("sql_param", sql_param_str);
			String pageno = request.getParameter("pageno");
			request.setAttribute("pageno", pageno);
		} catch (RuntimeException e1) {
			e1.printStackTrace();
		}
		request.setAttribute("t_role_Form", new t_role_Form());
		return "addpage";
	}

	public String doAdd(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		t_role_EditMap editMap = new t_role_EditMap();
		try {
			t_role_Form vo = null;
			vo = (t_role_Form) form;
			if (null == vo.getFunctionid()) {
				vo.setFunctionids(request.getParameterValues("functionid"));
			}
			editMap.add(vo);
		} catch (HibernateException e) {
			ActionErrors errors = new ActionErrors();
			errors.add("org.apache.struts.action.GLOBAL_ERROR",
					new ActionError("error.database.save", e.toString()));
			saveErrors(request, errors);
			e.printStackTrace();
			request.setAttribute("t_role_Form", form);
			return "addpage";
		}
		return "aftersave";
	}

	public String doQuery(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		try {
			String pageno = request.getParameter("pageno");
			request.setAttribute("pageno", pageno);
		} catch (RuntimeException e1) {
			e1.printStackTrace();
		}
		return "searchpage";
	}

	public String doEdit(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		try {
			request.setAttribute("sql_string", sql_string);
			request.setAttribute("sql_param", sql_param_str);
			String pageno = request.getParameter("pageno");
			request.setAttribute("pageno", pageno);
		} catch (RuntimeException e1) {
			e1.printStackTrace();
		}
		t_role_QueryMap query_map = new t_role_QueryMap();
		String uid = request.getParameter("id");
		t_role_Form vo = null;
		query_map.session.flush();
		vo = query_map.getByID(uid);
		request.setAttribute("t_role_Form", vo);
		return "editpage";
	}

	public String doUpdate(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		try {
			t_role_EditMap edit_map = new t_role_EditMap();
			t_role_Form vo = null;
			vo = (t_role_Form) form;
			if (null == vo.getFunctionid()) {
				vo.setFunctionids(request.getParameterValues("functionid"));
			}
			// System.out.println("vo.getFunctionid()="+vo.getFunctionid());
			edit_map.update(vo);
		} catch (HibernateException e) {
			ActionErrors errors = new ActionErrors();
			errors.add("org.apache.struts.action.GLOBAL_ERROR",
					new ActionError("error.database.save", e.toString()));
			saveErrors(request, errors);
			e.printStackTrace();
			request.setAttribute("t_role_Form", form);
			return "editpage";
		}
		return "aftersave";
	}

	public String doDelete(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		t_role_EditMap edit_map = new t_role_EditMap();
		String uid = request.getParameter("id");
		try {
			edit_map.delete(uid);
		} catch (HibernateException e) {
			ActionErrors errors = new ActionErrors();
			errors.add("org.apache.struts.action.GLOBAL_ERROR",
					new ActionError("error.database.save", e.toString()));
			saveErrors(request, errors);
			e.printStackTrace();
			return "list";
		}
		return "aftersave";
	}
}